// webpack.dll.config.js

const path = require('path');
const webpack = require('webpack');
const WebpackParallelUglifyPlugin = require('webpack-parallel-uglify-plugin');

// 需要打包到一起的js文件
const vendors = [
	'vue',
	'vue-router',
	'vuex',
	'vue-i18n',
	'axios',
	'echarts',
];

module.exports = {
	// 也可以设置多个入口，多个vendor，就可以生成多个bundle
	entry: {
		vendors,
	},

	// 输出文件的名称和路径
	output: {
		filename: '[name].wx-system.js',
		path: path.join(__dirname, '../../public/', 'static'),
		library: '[name]_[chunkhash]',
	},
	plugins: [
		// @link https://github.com/mishoo/UglifyJS2
		new WebpackParallelUglifyPlugin({
			uglifyJS: {
				mangle: false,
				output: {
					beautify: false,
					comments: false,
				},
				compress: {
					warnings: false,
					drop_console: true,
					collapse_vars: true,
					reduce_vars: true,
				},
			},
		}),
		// 这时候打包需要设置环境为production，因为像vue之类在
		// dev环境下会比prod环境多一些信息，在生产环境如果打包的是dev代码，
		// vue也会给出警告
		new webpack.DefinePlugin({
			'process.env': {
				NODE_ENV: '"production"',
			},
		}),

		/**
         * @link https://webpack.js.org/plugins/dll-plugin/
         */
		new webpack.DllPlugin({
			path: 'manifest.json',
			name: '[name]_[chunkhash]',
			context: __dirname,
		}),

		/**
         * 用于 webpack 1.0 到 2.0 迁移 loader 的配置变化
         *
         * @link https://doc.webpack-china.org/plugins/loader-options-plugin/
         */
		new webpack.LoaderOptionsPlugin({
			minimize: true,
		}),

		/**
         * 比对id的使用频率和分布来得出最短的id分配给使用频率高的模块
         *
         * @link https://github.com/webpack/docs/wiki/optimization
         */
		new webpack.optimize.OccurrenceOrderPlugin(),
	],
};
